<?php
//by willson 105328468@qq.com 2014/10/11
//index page interface

class ad extends core {

	public function __construct() {
		parent::__construct();
	}

	//读取广告
	public function index() {
		$now = time();
		$offset = (isset($_GET['offset']) && trim($_GET['offset'])) ? intval($_GET['offset']) : 0;
		$pagesize = (isset($_GET['pagesize']) && trim($_GET['pagesize'])) ? intval($_GET['pagesize']) : 8;
		$sql = "SELECT * FROM {$this->tbp}ad WHERE begin_time<='{$now}' AND end_time>='{$now}' ORDER BY sort ASC, id DESC LIMIT {$offset}, {$pagesize}";
		$ads = $this->db->get_results($sql);
		if ($ads) {
			foreach ($ads as $k => $ad) {
				//
			}
			$ads = add_domain_deep($ads, array("pic"));
		}
		success($ads);
	}

}
